#conding:utf-8
import os
from shutil import copyfile
from glob import glob
from optparse import OptionParser

def parse_args():
    parser = OptionParser()
    parser.add_option('-p', '--path', dest='path', default = None, help="image path")
    parser.add_option('-s', '--spath', dest='savepath', default=None, help="save path")
    parser.add_option('-d', '--dsample', dest='dsample',default=1, help="down sample ratio")
    options, args = parser.parse_args()
    return options

if __name__ == "__main__":
    opts = parse_args()
    src_imgs = glob(os.path.join(opts.path, '*.jpg'))
    for k in range(0,len(src_imgs),int(opts.dsample)):
        pure_name = os.path.split(src_imgs[k])[1].split('.')[0]
        copyfile(src_imgs[k], os.path.join(opts.savepath, pure_name+'.jpg'))



